/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mrp.productionPlanning.session;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import mrp.productionPlanning.entity.BackorderEntity;

/**
 *
 * @author Wei Haoyang
 */
@Stateless
@LocalBean
public class BackorderSessionBean {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext
    EntityManager em;
    @EJB
    DailyDetailSessionBean ddsb;
    BackorderEntity be;
    
    public void addBackorder(BackorderEntity b){
        em.persist(b);
    }
    
    public void updateBackorder(BackorderEntity b){
        em.merge(b);
    }
    
    public void removeBackorder(BackorderEntity b){
        em.remove(b);
    }
    
    public BackorderEntity getBackorderById(Long id){
        return em.find(BackorderEntity.class, id);
    }
    
    public float quantityToTime(int q, String type){
        float t = 0;
        if (type.equalsIgnoreCase("productA") || type.equalsIgnoreCase("productB")){
            t = q/12000;
        }
        else{
            t = q/9000;
        }
        return t;
    }
    
    public int timeToQuantity(float t, String type){
        int q = 0;
        String temp = null;
        if (type.equalsIgnoreCase("productA") || type.equalsIgnoreCase("productB")){
            temp = Float.toString(t*12000);
        }
        else{
            temp = Float.toString(t*9000);
        }
        q = Integer.valueOf(temp);
        return q;
    }
    
   
    
}
